﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class OnePointCrossover: CrossoverOperator
    {
        public OnePointCrossover(bool[] parent1, bool[] parent2)
        {
            this.parent1 = parent1;
            this.parent2 = parent2;
        }

        public OnePointCrossover()
        {

        }

        public override Pair<bool[], bool[]> doCrossover()
        {
            bool[] child1 = new bool[parent1.Length];
            bool[] child2 = new bool[parent1.Length];
            
            Random generator = new Random();
            
            int ciecie = generator.Next(parent2.Length-2);

            for (int i = 0; i <= ciecie; i++)
            {
                child1[i] = parent1[i];
                child2[i] = parent2[i];
            }

            for (int i = ciecie + 1; i < parent1.Length; i++)
            {
                child1[i] = parent2[i];
                child2[i] = parent1[i];
            }

            return new Pair<bool[], bool[]>(child1, child2);
        }
    }
}
